package com.example.mwavmedia.video;

import android.app.Activity;
import android.hardware.Camera;
import android.text.TextUtils;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.List;

public class YuvRecord {
    private static final String TAG = "YuvThread";

    private static class RecordThread extends Thread implements Camera.PreviewCallback{
        private Camera camera;
        private final String path;
        private FileOutputStream fileOutputStream;

        private final Activity activity;

        private final int id;

        private int width;
        private int height;

        private byte[] nv21Data;

        private boolean isStopRecord = false;

        public RecordThread(String path,Activity activity,int id){
            this.path = path;
            this.activity = activity;
            this.id = id;
        }

        @Override
        public void run() {
            super.run();
            initIO();
            initCamera();
            record();
        }

        private void initIO(){
            if (TextUtils.isEmpty(path)) return;
            File file = new File(path);
            if (file.exists()) file.delete();
            try {
                fileOutputStream = new FileOutputStream(path);
            }catch (FileNotFoundException fileNotFoundException){
                fileNotFoundException.printStackTrace();
                fileOutputStream = null;
            }
        }
        private void initCamera(){
            camera = Camera.open(id);
            if (camera == null) return;
            Camera.Parameters parameters = camera.getParameters();
            List<Camera.Size> sizeList = parameters.getSupportedPreviewSizes();

        }
        private void record(){

        }
        @Override
        public void onPreviewFrame(byte[] bytes, Camera camera) {

        }
    }
}
